package com.lucio.mybatis.simple;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * 实现Bean工厂
 */
public class ProxyBeanFactory implements FactoryBean {

    @Override
    public Object getObject() {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InvocationHandler handler = (proxy, method, args) -> "你被代理了 " + method.getName();
        return Proxy.newProxyInstance(classLoader, new Class[]{ UserDAO.class }, handler);
    }

    @Override
    public Class<?> getObjectType() {
        return UserDAO.class;
    }
}
